﻿/**
 * This is a part of MCServe, which is available under the Apache license 2.0.
 * With this code, you may do whatever you want as long as that is not in conflict with this license.
 * In addition, you should have a reference to the original project to include (http://mcserve.codeplex.com).
 * 
 * Author       : Lars Krämer ( Xe77a )
 * Website      : http://www.lkraemer.de
 * Project      : MCServe (http://mcserve.codeplex.com)
 * Copyright    : Copyright (c) 2013 lkraemer.de
 * License      : http://mcserve.codeplex.com/license
 * Description  : This is a part of the core functionality of the server
 */

using MCServeCore.Components;
using MCServeCore.Universal.Functions;
using System;
using System.Collections.ObjectModel;

namespace MCServeCore.PlayerObjects
{
    public class PlayerList
    {
        private ObservableCollection<Player> _Players = new ObservableCollection<Player>();
        public ObservableCollection<Player> Players
        {
            get
            {
                return _Players;
            }
        }

        /**
         * Konstruktor
         */
        public PlayerList()
        {
        }

        public void Add(Player player)
        {
            _Players.Add(player);
            GameServer.Console.SendMessage("A new Player joined the server : " + player.Name + " (" + player.Clan + ")", ServerConsole.OutputTarget.MessageLogAndConsole, ServerConsole.OutputTypes.Information);
        }

        public void Remove(Guid guid)
        {
            String Name = "";

            for (int i = _Players.Count - 1; i >= 0; i--)
            {
                if (_Players[i].Guid == guid)
                {
                    Name = _Players[i].Name;
                    _Players.RemoveAt(i);
                    GameServer.Console.SendMessage(Name + " has left the server", ServerConsole.OutputTarget.MessageLogAndConsole, ServerConsole.OutputTypes.Information);
                }
            }
        }
    }
}
